/**
 * @Author: LiMeng
 * @Date: 2017/4/14
 */
$(function () {
    var isMulti = $.getQueryParam('isMulti');
    var singleSelect = true;
    if (isMulti && isMulti.toString() === '1') {
        singleSelect = false;
    }
    //初始化加载datagrid
    $('#dg1').datagrid({
        method: 'post',
        url: ROOT_PATH + '/contractor/contractorInfo/list.shtml',
        queryParams: {
            sort: 'addTime',
            order: 'desc'
        },
        toolbar: '#toolbar',
        fitColumns: true,
        pagination: true,
        rownumbers: true,
        sortOrder: true,
        striped: true,
        fit: true,
        singleSelect: singleSelect,
        columns: [[
            {field: 'ckid', checkbox: true},
            {field: 'code', title: '承包商代码', width: 80, sortable: true},
            {field: 'name', title: '承包商名称', width: 100, sortable: true},
            {field: 'address', title: '地址', width: 100}
        ]]
    });
    $('#btn_clear').on("click", function () {
        $('#tb1').form('reset');
        $('#tb2').form('reset');
    });
    $('#btn_search').on("click", function () {
        $('#dg1').datagrid('reload', $('#tb1,#tb2').find(':input').serializeJson());
    });
    $('#btn_advanced_search').on("click", function () {
        $('#tb2').toggle();
        $('#dg1').datagrid('resize');
    });
    $('#btn_save').on("click", function () {
        var $selected = $('#dg1').datagrid('getSelections');
        if ($selected.length === 0) {
            layer.alert("请选择一条数据！");
            return;
        }
        WindowManager.closeLayer({
            returnValue: $selected
        });
    });
});